package verappdesktop.views;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.JPanel;

import verappdesktop.utils.CheckBoxWithVariable;
import verappdesktop.utils.VariableDataSet;
import verappdesktop.core.Variable;
import verappdesktop.core.VerappDesktop;

public class OptionsView extends JPanel implements ActionListener{
	private GraphView gv;
	
	private OptionsView(){}
	
	public OptionsView(GraphView gv){
		this.gv = gv;
		
		CheckBoxWithVariable cb;
		
		//Create iterator and use it to loop through all variables and create the appropriate checkboxes.
		List<Variable> variables = VerappDesktop.getAvailableVariables();
		for (Variable var : variables){
			cb = new CheckBoxWithVariable(var);
			cb.addActionListener(this);
			add(cb);
		}
	}

	/**
	 * Fired when a checkbox is (un)selected.
	 */
	@Override
	public void actionPerformed(ActionEvent evt) {
		CheckBoxWithVariable cb = (CheckBoxWithVariable)evt.getSource();
		//If a checkbox has been selected, make sure that it's being drawn.
		if (cb.isSelected()){
			Map<Double,Double> map = new TreeMap<Double,Double>();
			map.put(new Double(1), new Double(2));
			map.put(new Double(2), new Double(3));
			map.put(new Double(3), new Double(4));
			gv.addVariable(new VariableDataSet(cb.getVariable(), map));
		}
		//If a checkbox has been unselected, make sure that it's no longer being drawn.
		else {
			gv.removeVariable(cb.getVariable());
		}
	}
}
